import request from '../utils/request';

export async function searchCouponCode(shopId, data) {
  return await request(`/shop/${shopId}/couponCode`, {
    params: {
      ...data, filter: JSON.stringify({ status: { $in: [1, 2, 3] }, ...data.filter }),
    },
  });
}

export async function updateCouponCode(shopId, id, body) {
  body.useData = body.useData || {};
  return await request(`/shop/${shopId}/couponCode/${id}`, {
    method: 'put',
    body: {
      status: body.status,
      flow_no: body.flow_no,
      'useData.userId': body.useData.userId,
      'useData.use_date': body.useData.use_date,
      'useData.branch_no': body.useData.branch_no,
      'useData.saleman_id': body.useData.saleman_id,
      'useData.saleman_name': body.useData.saleman_name,
      'useData.phone': body.useData.phone,
      'useData.username': body.useData.username,
    },
  });
}

export async function searchCoupon(shopId, data) {
  return await request(`/shop/${shopId}/coupon`, {
    params: {
      ...data, filter: JSON.stringify({ status: { $in: [1, 2, 3] }, ...data.filter }),
    },
  });
}

export async function sendCoupon(shopId, id, card_id, saleman_id, saleman_name) {
  return await request(`/shop/${shopId}/coupon/${id}/send`, {
    method: 'post',
    body: {
      sendType: 3, // 导购优惠券类型
      card_id,
      saleman_id,
      saleman_name,
    },
  });
}
